package sharping.appilog.Adapter;

import java.util.ArrayList;

import sharping.appilog.R;
import sharping.appilog.DataTree.BizMenuData;
import sharping.appilog.ListItem.BizMenuItem;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class RBizMenuAdapter extends BaseAdapter {

	private Context context;
	private LayoutInflater inflater;
	private ArrayList<BizMenuData> items;

	public RBizMenuAdapter(Context context, ArrayList<BizMenuData> items,
			LayoutInflater inflater) {
		this.context = context;
		this.inflater = inflater;
		this.items = items;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return items.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return items.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}
	
	public void setItems(ArrayList<BizMenuData> items) {
		this.items = items;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		BizMenuItem v;

		if (convertView == null) {
			convertView = inflater.inflate(R.layout.fragment_bizmenu, null);
			v = new BizMenuItem(context, convertView);

			convertView.setTag(v);
		} else {
			v = (BizMenuItem) convertView.getTag();
		}

		v.setItem(items.get(position));
		v.setParam();

		return convertView;
	}

}
